package com.ruoyi.auth.service.impl;

import com.ruoyi.auth.domain.ClassStudent;
import com.ruoyi.auth.mapper.ClassStudentMapper;
import com.ruoyi.auth.service.IClassStudentService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SnowflakeIdUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 班级学员明细Service业务层处理
 *
 * @author WorrilessGo
 * @date 2025-09-24
 */
@Service
public class ClassStudentServiceImpl implements IClassStudentService {
    private static final Logger log = LoggerFactory.getLogger(ClassStudentServiceImpl.class);

    @Autowired
    private ClassStudentMapper classStudentMapper;


    /**
     * 查询班级学员明细
     *
     * @param classStudentId 班级学员明细主键
     * @return 班级学员明细
     */
    @Override
    public ClassStudent selectClassStudentByClassStudentId(String classStudentId) {
        return classStudentMapper.selectClassStudentByClassStudentId(classStudentId);
    }

    /**
     * 查询班级学员明细列表
     *
     * @param classStudent 班级学员明细
     * @return 班级学员明细
     */
    @Override
    public List<ClassStudent> selectClassStudentList(ClassStudent classStudent) {
        return classStudentMapper.selectClassStudentList(classStudent);
    }

    /**
     * 新增班级学员明细
     *
     * @param classStudent 班级学员明细
     * @return 结果
     */
    @Override
    public int insertClassStudent(ClassStudent classStudent) {
        classStudent.setCreateTime(DateUtils.getNowDate());
        return classStudentMapper.insertClassStudent(classStudent);
    }

    /**
     * 修改班级学员明细
     *
     * @param classStudent 班级学员明细
     * @return 结果
     */
    @Override
    public int updateClassStudent(ClassStudent classStudent) {
        classStudent.setUpdateTime(DateUtils.getNowDate());
        return classStudentMapper.updateClassStudent(classStudent);
    }

    /**
     * 批量删除班级学员明细
     *
     * @param classStudentIds 需要删除的班级学员明细主键
     * @return 结果
     */
    @Override
    public int deleteClassStudentByClassStudentIds(String[] classStudentIds) {
        return classStudentMapper.deleteClassStudentByClassStudentIds(classStudentIds);
    }

    /**
     * 删除班级学员明细信息
     *
     * @param classStudentId 班级学员明细主键
     * @return 结果
     */
    @Override
    public int deleteClassStudentByClassStudentId(String classStudentId) {
        return classStudentMapper.deleteClassStudentByClassStudentId(classStudentId);
    }
    /**
     * 通过班级id获取学员id
     * lqx
     */
    @Override
    public List<String> selectStudentIdsByClassId(String classId) {
        return classStudentMapper.selectStudentIdsByClassId(classId);
    }

    /**
     * 通过班级id和学员id查询
     * @param studentId
     * @param trainingClassId
     * @return
     */
    @Override
    public List<ClassStudent> selectClassStudentByClassStudentIdAndClassId(String studentId, String trainingClassId) {
        return classStudentMapper.selectClassStudentByClassStudentIdAndClassId(studentId,trainingClassId);
    }

    /**
     * 检查是否有有效的搜索条件
     */
    private boolean hasSearchConditions(String studentName, String phonenumber, String idNumber) {
        return StringUtils.hasText(studentName) ||
                StringUtils.hasText(phonenumber) ||
                StringUtils.hasText(idNumber);
    }
}
